/**
 * @param {number[]} candidates
 * @param {number} target
 * @return {number[][]}
 */
var combinationSum2 = function (candidates, target) {
	candidates.sort((a, b) => a - b) // 方便去重
	const res = []
	const dfs = (start, comb, sum) => {
		if (sum >= target) {
			if (sum === target) {
				res.push(comb.slice())
			}
			return
		}
		for (let i = start; i < candidates.length; i++) {
			// 防止 i - 1 越界 忽略同一层的重复选项 [1,2,2]
			if (i - 1 >= start && candidates[i - 1] === candidates[i]) {
				continue
			}
			comb.push(candidates[i])
			dfs(i + 1, comb, sum + candidates[i])
			comb.pop()
		}
	}
	dfs(0, [], 0)
	return res
}
const res = combinationSum2([10, 1, 2, 7, 6, 1, 5], 8)
console.log('combinationSum2 :>>', res)
